<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:p="http://www.springframework.org/schema/p"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:task="http://www.springframework.org/schema/task"	
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
						http://www.springframework.org/schema/beans/spring-beans.xsd  
						http://www.springframework.org/schema/tx 
						http://www.springframework.org/schema/tx/spring-tx.xsd
						http://www.springframework.org/schema/context 
						http://www.springframework.org/schema/context/spring-context.xsd
						http://www.springframework.org/schema/aop 
						http://www.springframework.org/schema/aop/spring-aop.xsd 
						http://www.springframework.org/schema/task  
						http://www.springframework.org/schema/task/spring-task-3.0.xsd">

						
					
						
			  
	
	
	<!-- Resolves localized messages*.properties and application.properties files in the application to allow for internationalization. 
    The messages*.properties files translate Roo generated messages which are part of the admin interface, the 
    application.properties resource bundle localizes all application specific messages such as entity names and menu items. -->
    <bean class="org.springframework.context.support.ReloadableResourceBundleMessageSource" id="messageSource" p:basenames="WEB-INF/i18n/messages,WEB-INF/i18n/application" p:fallbackToSystemLocale="false" p:cacheSeconds="1"/>
						
						

	<!-- PropertyConfigurer for the DAO -->
	<context:property-placeholder location="file:/JDESURVEY/config/configuration.properties"/>
					
	<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
		<property name="host" value="${email.host}"/>
		<property name="port" value="${email.port}"/>
		<property name="username" value="${email.username}"/>
		<property name="password" value="${email.password}"/>
		<property name="javaMailProperties">
			<props>
				<!-- Use SMTP transport protocol -->
				<prop key="mail.transport.protocol">smtp</prop>
				<prop key="mail.smtp.from">${email.smtp.from}</prop>
				<!-- Use SMTP-AUTH to authenticate to SMTP server -->
				<prop key="mail.smtp.auth">true</prop>
				<!-- Use TLS to encrypt communication with SMTP server
				<prop key="mail.smtp.starttls.enable">true</prop> -->
				<prop key="mail.debug">false</prop>
			</props>
		</property>
	</bean>

	
	
	<context:component-scan base-package="com.jd.survey">
    <context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
	<context:exclude-filter type="aspectj"  expression="com.jd.survey.dao.survey.QuestionStatisticDAOImp || com.jd.survey.dao.survey.QuestionStatisticMSSQLDAOImp"/>
    </context:component-scan>
 	<!-- Use this Bean when using MySql -->
	<bean class="com.jd.survey.dao.survey.QuestionStatisticDAOImp" />
	
	<!-- Use this Bean when using MSSQL 
	<bean class="com.jd.survey.dao.survey.QuestionStatisticMSSQLDAOImp" />
	-->
	
	<!-- ******************************************************************** -->
	<!-- Mark bean transactions as annotation driven -->
	<tx:annotation-driven transaction-manager="transactionManager"/>
	
		

	
	
	<!-- ******************************************************************** -->
	<!-- Setup the transaction manager -->
	<!-- ******************************************************************** -->
		<!-- Using Atomikos Transaction Manager -->
		<bean class="com.atomikos.icatch.jta.UserTransactionManager" destroy-method="close" id="atomikosTransactionManager" init-method="init">
			<property name="forceShutdown" value="true"/>
			<property name="startupTransactionService" value="true"/>
			<property name="transactionTimeout" value="1000"/>
		</bean>
		
		<bean class="com.atomikos.icatch.jta.UserTransactionImp" id="atomikosUserTransaction"/>
		
		<!-- Configure the Spring framework to use JTA transactions from Atomikos -->
		<bean class="org.springframework.transaction.jta.JtaTransactionManager" id="transactionManager">
			<property name="transactionManager" ref="atomikosTransactionManager"/>
			<property name="userTransaction" ref="atomikosUserTransaction"/>
			<property name="transactionSynchronizationName" value="SYNCHRONIZATION_ON_ACTUAL_TRANSACTION"/>
		</bean>
	
 	<!-- ******************************************************************** -->
	<!-- Setup a data source -->
	<!-- ******************************************************************** -->


	
	
				<!-- Using Apache DBCP Data Sources 
				<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" name="basicDataSource">
					<property name="driverClassName" value="${database.connection.driver_class}"/>
					<property name="username" value="${database.connection.username}"/>
					<property name="password" value="${database.connection.password}"/>
					<property name="url" value="${database.connection.url}"/>
					<property name="maxIdle" value="${database.minPoolSize}"/>
					<property name="maxActive" value="${database.maxPoolSize}"/>
				</bean>
				-->
				
				 <bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" name="basicDataSource">
			        <property name="driverClassName" value="${database.driverClassName}"/>
			        <property name="url" value="${database.url}"/>
			        <property name="username" value="${database.username}"/>
			        <property name="password" value="${database.password}"/>
			        <property name="testOnBorrow" value="true"/>
			        <property name="testOnReturn" value="true"/>
			        <property name="testWhileIdle" value="true"/>
			        <property name="timeBetweenEvictionRunsMillis" value="1800000"/>
			        <property name="numTestsPerEvictionRun" value="3"/>
			        <property name="minEvictableIdleTimeMillis" value="1800000"/>
			        <property name="validationQuery" value="SELECT 1"/>
					
			    </bean>
		
	
	<!-- ******************************************************************** -->
	<!-- Setup each persistence unit -->
	<!-- ******************************************************************** -->


	
	<!-- Configure a JPA vendor adapter -->
	<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" id="hibernateJpaVendorAdapter">
		<property name="showSql" value="${database.show_sql}"/>
		<property name="generateDdl" value="${database.generateDdl}"/>
		<property name="databasePlatform" value="${database.dialect}"/>
	</bean>
	
	
	<!-- EntityManager Factory that brings together the persistence unit, datasource, and JPA Vendor -->
	<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactoryBean">
		<property name="dataSource" ref="basicDataSource"/>
		<property name="persistenceUnitName" value="persistenceUnit"/>
		<property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter"/>
			<property name="jpaPropertyMap">
				<map>
					<entry key="hibernate.transaction.manager_lookup_class" value="com.atomikos.icatch.jta.hibernate3.TransactionManagerLookup"/>
					<entry key="hibernate.connection.release_mode" value="on_close"/>
					<entry key="hibernate.show_sql" value="true"/>
				</map>
			</property>
	</bean>
	
	
	
	
	
	
	
	
	
	
	

	<!-- Velocity Database Template Loader -->
	<bean id="templateLoader" class="org.apache.velocity.runtime.resource.loader.DataSourceResourceLoader">
		<property name="dataSource" ref="basicDataSource"/>
	</bean>	
	
	
	<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
		<property name="velocityProperties">
			<map>
				<entry key="resource.loader" value="ds"/>
				<entry key="ds.resource.loader.instance"  value-ref="templateLoader"/>
				<entry key="ds.resource.loader.resource.table" value="velocity_template"/>
				<entry key="ds.resource.loader.resource.keycolumn" value="template_name"/>
				<entry key="ds.resource.loader.resource.timestampcolumn" value="template_timestamp"/>
				<entry key="ds.resource.loader.resource.templatecolumn" value="template_definition"/>
				<entry key="ds.resource.loader.cache" value="false"/>
				<entry key="ds.resource.loader.modificationCheckInterval" value="10"/>
			</map>
		</property> 
	</bean>					
</beans>

